/*
 * @Author: caijw 
 * @Date: 2018-11-29 20:28:52 
 * @Last Modified by: caijw
 * @Last Modified time: 2019-01-08 23:00:28
 */
import * as types from '../action-types';
import { getStore,getStoreDetail } from '../../api/index';
//获取用户信息
export function fetchAmbitusList() {
  return function(dispatch, getState) {
    //先获取数据显示加载内容
    dispatch({type: types.FETCH_AMBITUS});
    let {page, kw, code, lat, lng} = getState().ambitus.ambitus;
    //错误处理
    if(!lat){
      lat  = '';
      lng = '';
    }
    getStore(page,kw,code, lat, lng).then(payload=>{
      dispatch({type: types.FETCH_AMBITUS_FULFILLED, payload: payload});
    })
    
  }
}


export function fetchAmbitusDetail(id) {
  return function(dispatch) {
    //先获取数据显示加载内容
    dispatch({type: types.FETCH_AMBITUS_DETAIL});
    getStoreDetail(id).then(payload=>{
      dispatch({type: types.FETCH_AMBITUS_DETAIL_FULFILLED, payload: payload});
    })
    
  }
}